package ar.com.spsolutions.splilabrary.view.application.configuration;

import org.apache.wicket.markup.html.WebPage;

import ar.com.spsolutions.splilabrary.view.application.SPApplication;
import ar.com.spsolutions.splilabrary.view.pages.BasePage;
import ar.com.spsolutions.splilabrary.view.pages.Home;
import ar.com.spsolutions.splilabrary.view.pages.author.AuthorManager;
import ar.com.spsolutions.splilabrary.view.pages.book.BookManager;
import ar.com.spsolutions.splilabrary.view.pages.book.loan.LoanManager;
import ar.com.spsolutions.splilabrary.view.pages.category.CategoryManager;
import ar.com.spsolutions.splilabrary.view.pages.user.UserManager;

public class MapperConfigurator extends Configurator {

	public MapperConfigurator(final SPApplication application) {
		super(application);
	}

	@Override
	protected void initialize(final SPApplication app) {
		this.addPage("Home", Home.class);
		this.addPage("Loan", LoanManager.class);
		// para todos:

		// abm solo lo ve el admin:
		this.addPage("User", UserManager.class);
		this.addPage("Author", AuthorManager.class);
		this.addPage("Category", CategoryManager.class);
		this.addPage("Book", BookManager.class);
	}

	private void addPage(final String pageName,
			final Class<? extends BasePage> page) {

		this.mountUrl(pageName, page, "");
		BasePage.addPage(page);
	}

	private void mountUrl(final String mountPath,
			final Class<? extends WebPage> pageClass,
			final String... parameters) {
		this.getApplication().getMounterURL()
				.mount(mountPath, pageClass, parameters);
	}

}
